<?php
//define('CMSPAD_DEBUG', true);
$_CONFIG = array();
require_once('./kernel/global.php');
cmspad_import('Controller');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if(isset($_POST['cpdp'])){
		echo Controller::proxy();
	}else{
		$controller = Controller::getInstance();
		$controller->processRequests();
	}
}else{
	
	$pathinfo = isset($_SERVER['ORIG_PATH_INFO'])?$_SERVER['ORIG_PATH_INFO']:(isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:'');
	$allowGZip = isset($_CONFIG['SYSTEM']['USE_GZIP']) && $_CONFIG['SYSTEM']['USE_GZIP'] === true && extension_loaded('zlib') && strstr($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip');
	if(strlen($pathinfo) > 8 && substr($pathinfo,0,8) == '/kernel/'){
		if(Controller::cache($pathinfo, $allowGZip)){
			exit();
		}
	}
	cmspad_import('Dispatcher');
	$dispatcher = new Dispatcher();
	if($allowGZip){
		ob_start('ob_gzhandler');
	}else{
		ob_start();
	}
	$dispatcher->dispatch($pathinfo);
	ob_end_flush();
}
?>